package com.peng.design.visitor;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

/**
 * App
 *
 * @author: lupeng10
 * @create: 2023-06-08 14:49
 */
@Slf4j
public class App {

    @Test
    public void test1() {
        CommanderUnit commanderUnit = new CommanderUnit("团长-李云龙",
                new SergeantUnit("一营长-张大彪", new SoldierUnit("一营士兵-张三"), new SoldierUnit("一营士兵-李四")),
                new SergeantUnit("警卫连长-和尚", new SoldierUnit("警卫连-王五"), new SoldierUnit("警卫连-冯六")),
                new SergeantUnit("骑兵连长-孙德胜", new SoldierUnit("骑兵连-马七"), new SoldierUnit("骑兵连长-赵八"))
        );
        // commanderUnit.accept(new CommanderVisitor());
        // commanderUnit.accept(new SergeantVisitor());
        // commanderUnit.accept(new SoldierVisitor());

        commanderUnit.accept(new UnitVisitorAdapter() {
            @Override
            public void visit(CommanderUnit commanderUnit) {
                log.info("访问CommanderUnit {}", commanderUnit.getName());
            }
        });

        commanderUnit.accept(new UnitVisitorAdapter() {
            @Override
            public void visit(SergeantUnit sergeantUnit) {
                log.info("访问SergeantUnit {}", sergeantUnit.getName());
            }
        });

        commanderUnit.accept(new UnitVisitorAdapter() {
            @Override
            public void visit(SoldierUnit soldierUnit) {
                log.info("访问SoldierUnit {}", soldierUnit.getName());
            }
        });
    }

    @Test
    public void test2() {
        Children children = new Children();
        children.print1();
        children.print2();
    }


    static class Father {
        public void print1() {
            System.out.println(this);
        }
    }

    static class Children extends Father {
        public void print2() {
            System.out.println(this);
        }
    }

}
